package com.cdream.basic.algorithm.leetcode.array;


import java.util.*;

/**
 * @author cdream
 * @date 10/31/21
 */
public class Question500 {
    static Set<Character> set1 = new HashSet<>();
    static Set<Character> set2 = new HashSet<>();
    static Set<Character> set3 = new HashSet<>();
    static {
        for (char c : "qwertyuiop".toCharArray()) {
            set1.add(c);
        }
        for (char c : "asdfghjkl".toCharArray()) {
            set2.add(c);
        }
        for (char c : "zxcvbnm".toCharArray()) {
            set3.add(c);
        }

    }
    public String[] findWords(String[] words) {
        List<String> res = new ArrayList<>();
        for (String word : words) {
            if (wordInSet(set1,word)||wordInSet(set2,word)||wordInSet(set3,word)){
                res.add(word);
            }
        }
        return res.toArray(new String[0]);
    }

    private boolean wordInSet(Set<Character> set1, String word) {
        for (char c : word.toLowerCase().toCharArray()) {
            if (!set1.contains(c)){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString("你a".getBytes()));
        new String("你a".getBytes());
    }
}
